home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / phoenix.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  7KB  |  302 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. /* from sndhrdw/pleiads.c */
  13. WRITE_HANDLER( pleiads_sound_control_c_w );
  14.  
  15. static unsigned char *ram_page1;
  16. static unsigned char *ram_page2;
  17. static unsigned char *current_ram_page;
  18. static int current_ram_page_index;
  19. static unsigned char bg_scroll;
  20. static int palette_bank;
  21. static int protection_question;
  22.  
  23.  
  24. #define BACKGROUND_VIDEORAM_OFFSET   0x0800
  25.  
  26.  
  27. /***************************************************************************
  28.  
  29.   Convert the color PROMs into a more useable format.
  30.  
  31.   Phoenix has two 256x4 palette PROMs, one containing the high bits and the
  32.   other the low bits (2x2x2 color space).
  33.   The palette PROMs are connected to the RGB output this way:
  34.  
  35.   bit 3 --
  36.         -- 270 ohm resistor  -- GREEN
  37.         -- 270 ohm resistor  -- BLUE
  38.   bit 0 -- 270 ohm resistor  -- RED
  39.  
  40.   bit 3 --
  41.         -- GREEN
  42.         -- BLUE
  43.   bit 0 -- RED
  44.  
  45.   plus 270 ohm pullup and pulldown resistors on all lines
  46.  
  47. ***************************************************************************/
  48. void phoenix_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  49. {
  50.     int i;
  51.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  52.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  53.  
  54.  
  55.     for (i = 0;i < Machine->drv->total_colors;i++)
  56.     {
  57.         int bit0,bit1;
  58.  
  59.  
  60.         bit0 = (color_prom[0] >> 0) & 0x01;
  61.         bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  62.         *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  63.         bit0 = (color_prom[0] >> 2) & 0x01;
  64.         bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  65.         *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  66.         bit0 = (color_prom[0] >> 1) & 0x01;
  67.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  68.         *(palette++) = 0x55 * bit0 + 0xaa * bit1;
  69.  
  70.         color_prom++;
  71.     }
  72.  
  73.     /* first bank of characters use colors 0-31 and 64-95 */
  74.     for (i = 0;i < 8;i++)
  75.     {
  76.         int j;
  77.  
  78.  
  79.         for (j = 0;j < 2;j++)
  80.         {
  81.             COLOR(0,4*i + j*4*8) = i + j*64;
  82.             COLOR(0,4*i + j*4*8 + 1) = 8 + i + j*64;
  83.             COLOR(0,4*i + j*4*8 + 2) = 2*8 + i + j*64;
  84.             COLOR(0,4*i + j*4*8 + 3) = 3*8 + i + j*64;
  85.         }
  86.     }
  87.  
  88.     /* second bank of characters use colors 32-63 and 96-127 */
  89.     for (i = 0;i < 8;i++)
  90.     {
  91.         int j;
  92.  
  93.  
  94.         for (j = 0;j < 2;j++)
  95.         {
  96.             COLOR(1,4*i + j*4*8) = i + 32 + j*64;
  97.             COLOR(1,4*i + j*4*8 + 1) = 8 + i + 32 + j*64;
  98.             COLOR(1,4*i + j*4*8 + 2) = 2*8 + i + 32 + j*64;
  99.             COLOR(1,4*i + j*4*8 + 3) = 3*8 + i + 32 + j*64;
  100.         }
  101.     }
  102. }
  103.  
  104.  
  105. /***************************************************************************
  106.  
  107.   Start the video hardware emulation.
  108.  
  109. ***************************************************************************/
  110. int phoenix_vh_start(void)
  111. {
  112.     if ((ram_page1 = malloc(0x1000)) == 0)
  113.         return 1;
  114.  
  115.     if ((ram_page2 = malloc(0x1000)) == 0)
  116.         return 1;
  117.  
  118.     current_ram_page = 0;
  119.     current_ram_page_index = -1;
  120.  
  121.     videoram_size = 0x0340;
  122.     return generic_vh_start();
  123. }
  124.  
  125.  
  126.  
  127. /***************************************************************************
  128.  
  129.   Stop the video hardware emulation.
  130.  
  131. ***************************************************************************/
  132. void phoenix_vh_stop(void)
  133. {
  134.     free(ram_page1);
  135.     free(ram_page2);
  136.  
  137.     ram_page1 = 0;
  138.     ram_page2 = 0;
  139.  
  140.     generic_vh_stop();
  141. }
  142.  
  143.  
  144.  
  145. READ_HANDLER( phoenix_paged_ram_r )
  146. {
  147.     return current_ram_page[offset];
  148. }
  149.  
  150.  
  151. WRITE_HANDLER( phoenix_paged_ram_w )
  152. {
  153.     if ((offset >= BACKGROUND_VIDEORAM_OFFSET) &&
  154.         (offset <  BACKGROUND_VIDEORAM_OFFSET + videoram_size))
  155.     {
  156.         /* Background video RAM */
  157.         if (data != current_ram_page[offset])
  158.         {
  159.             dirtybuffer[offset - BACKGROUND_VIDEORAM_OFFSET] = 1;
  160.         }
  161.     }
  162.  
  163.     current_ram_page[offset] = data;
  164. }
  165.  
  166.  
  167. WRITE_HANDLER( phoenix_videoreg_w )
  168. {
  169.     if (current_ram_page_index != (data & 1))
  170.     {
  171.         /* Set memory bank */
  172.         current_ram_page_index = data & 1;
  173.  
  174.         current_ram_page = current_ram_page_index ? ram_page2 : ram_page1;
  175.  
  176.         memset(dirtybuffer,1,videoram_size);
  177.     }
  178.  
  179.     if (palette_bank != ((data >> 1) & 1))
  180.     {
  181.         palette_bank = (data >> 1) & 1;
  182.  
  183.         memset(dirtybuffer,1,videoram_size);
  184.     }
  185.  
  186.     protection_question = data & 0xfc;
  187.  
  188.     /* I think bits 2 and 3 are used for something else in Pleiads as well,
  189.        they are set in the routine starting at location 0x06bc */
  190.  
  191.     /* send two bits to sound control C (not sure if they are there) */
  192.     pleiads_sound_control_c_w(offset, data);
  193. }
  194.  
  195.  
  196. WRITE_HANDLER( phoenix_scroll_w )
  197. {
  198.     bg_scroll = data;
  199. }
  200.  
  201.  
  202. READ_HANDLER( phoenix_input_port_0_r )
  203. {
  204.     int ret = input_port_0_r(0) & 0xf7;
  205.  
  206.     /* handle Pleiads protection */
  207.     switch (protection_question)
  208.     {
  209.     case 0x00:
  210.     case 0x20:
  211.         /* Bit 3 is 0 */
  212.         break;
  213.     case 0x0c:
  214.     case 0x30:
  215.         /* Bit 3 is 1 */
  216.         ret    |= 0x08;
  217.         break;
  218.     default:
  219.         logerror("Unknown protection question %02X at %04X\n", protection_question, cpu_get_pc());
  220.     }
  221.  
  222.     return ret;
  223. }
  224.  
  225.  
  226. /***************************************************************************
  227.  
  228.   Draw the game screen in the given osd_bitmap.
  229.   Do NOT call osd_update_display() from this function, it will be called by
  230.   the main emulation engine.
  231.  
  232. ***************************************************************************/
  233. void phoenix_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  234. {
  235.     int offs;
  236.  
  237.  
  238.     /* for every character in the Video RAM, check if it has been modified */
  239.     /* since last time and update it accordingly. */
  240.     for (offs = videoram_size - 1;offs >= 0;offs--)
  241.     {
  242.         if (dirtybuffer[offs])
  243.         {
  244.             int sx,sy,code;
  245.  
  246.  
  247.             dirtybuffer[offs] = 0;
  248.  
  249.             code = current_ram_page[offs + BACKGROUND_VIDEORAM_OFFSET];
  250.  
  251.             sx = offs % 32;
  252.             sy = offs / 32;
  253.  
  254.             drawgfx(tmpbitmap,Machine->gfx[0],
  255.                     code,
  256.                     (code >> 5) + 8 * palette_bank,
  257.                     0,0,
  258.                     8*sx,8*sy,
  259.                     0,TRANSPARENCY_NONE,0);
  260.         }
  261.     }
  262.  
  263.  
  264.     /* copy the character mapped graphics */
  265.     {
  266.         int scroll;
  267.  
  268.  
  269.         scroll = -bg_scroll;
  270.  
  271.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  272.     }
  273.  
  274.  
  275.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  276.     for (offs = videoram_size - 1;offs >= 0;offs--)
  277.     {
  278.         int sx,sy,code;
  279.  
  280.  
  281.         code = current_ram_page[offs];
  282.  
  283.         sx = offs % 32;
  284.         sy = offs / 32;
  285.  
  286.         if (sx >= 1)
  287.             drawgfx(bitmap,Machine->gfx[1],
  288.                     code,
  289.                     (code >> 5) + 8 * palette_bank,
  290.                     0,0,
  291.                     8*sx,8*sy,
  292.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  293.         else
  294.             drawgfx(bitmap,Machine->gfx[1],
  295.                     code,
  296.                     (code >> 5) + 8 * palette_bank,
  297.                     0,0,
  298.                     8*sx,8*sy,
  299.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  300.     }
  301. }
  302.